package com.ai.tikai.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.stream.Stream;

public enum AuditSuggestion {
    REJECT("reject", "拒绝/拦截"),
    PASS("pass", "通过");
    @EnumValue
    private final String value;
    private final String description;

    AuditSuggestion(String value, String description) {
        this.value = value;
        this.description = description;
    }

    // @JsonValue 注解告诉Jackson序列化时使用这个方法返回值
    @JsonCreator
    public static AuditSuggestion fromValue(String value) {
        if (value == null) {
            return null;
        }
        // 将传入的字符串统一转为小写再进行匹配
        return Stream.of(AuditSuggestion.values())
                .filter(s -> s.value.equalsIgnoreCase(value)) // 使用忽略大小写的比较
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unknown enum type " + value + ", Allowed values are " + Stream.of(values()).map(e -> e.value).toList()));
    }

//    @JsonValue
//    public String getValue() {
//        return value;
//    }

    public String getDescription() {
        return description;
    }
}
